package com.mvprxjavartrofit.ui.home;

import android.content.ContentResolver;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.mvprxjavartrofit.R;
import com.mvprxjavartrofit.base.BaseActivity;
import com.mvprxjavartrofit.entity.User;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Administrator
 * At 2016/10/20/9:59/2016
 * Project test
 */
public class HomeActivity extends BaseActivity<HomePresenter, HomeModel> implements HomeContract.View {

    private ContentResolver resolver;

    @BindView(R.id.btn_insert)
    Button btnInsert;
    @BindView(R.id.btn_query)
    Button btnQuery;
    @BindView(R.id.btn_delete)
    Button btnDetele;
    @BindView(R.id.btn_update)
    Button btnUpdate;
    @BindView(R.id.tv_show)
    TextView tvShow;


    @Override
    public int getLayoutId() {
        return R.layout.activity_home;
    }

    @Override
    public void initView() {
        unbinder = ButterKnife.bind(this);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        resolver = this.getContentResolver();
    }

    @OnClick({R.id.btn_insert, R.id.btn_query, R.id.btn_delete
            , R.id.btn_update, R.id.tv_show})
    public void onClick(View view) {
        switch(view.getId()) {
            case R.id.btn_insert:
                presenter.insert(resolver);
                break;
            case R.id.btn_query:
                presenter.query(resolver, "name=?", new String[]{"YYY"});
//                presenter.query(resolver, null, null);
                break;
            case R.id.btn_delete:
                presenter.delete(resolver, null, null);
                break;
            case R.id.btn_update:
                presenter.update(resolver, "name=?", new String[]{"XXX"});
        }
    }

    @Override
    public void showQuery(List<User> users) {
        tvShow.setText(users.toString());
    }
}
